package com.example.exam.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.exam.mapper.ManagementUserMapper;
import com.example.exam.pojo.ManagementUser;
import com.example.exam.service.ManagementUserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @date 2023/05/07
 */
@Service
public class ManagementUserServiceImpl extends ServiceImpl<ManagementUserMapper, ManagementUser> implements ManagementUserService {

    @Override
    public ManagementUser searchAllByUsername(String username) {
        QueryWrapper<ManagementUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public List<ManagementUser> searchAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public void insert(ManagementUser user) {
        baseMapper.insert(user);
    }

    @Override
    public void update(ManagementUser user) {
        UpdateWrapper<ManagementUser> wrapper = new UpdateWrapper<>();
        wrapper.eq("username", user.getUsername());
        baseMapper.update(user, wrapper);
    }

    @Override
    public void del(String username) {
        QueryWrapper<ManagementUser> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        baseMapper.delete(wrapper);
    }
}
